package cn.zyq.stater.config;

import cn.zyq.stater.bean.User4;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

@Configuration
@PropertySource(value = "classpath:jdbc.properties",ignoreResourceNotFound = false)
public class Config4_PropertySource {


    @Value("${test4.username}")
    private String name;

    @Value("${test4.password}")
    private String password;




    //用Environment对象的getProperty()可以获取@PropertySource导入的properties文件内容(获得运行环境中的变量<包括jvm及操作系统中的一些变量信息>)
    @Autowired
    Environment environment;

    @Bean
    public User4 createUser4(){
        String name2=environment.getProperty("test4.username");
        String password2=environment.getProperty("test4.password");
        User4 user=new User4(name2,password2);
        System.out.println(name+"::"+password);
        System.out.println(user);
        return user;
    }


}